package base.Day04;

import java.util.Random;

public class Guessing
{
    public static void main(String[] args)
    {
        Guessing guessing = new Guessing();
        guessing.test();
    }


    public void test()
    {
        int target = new Random().nextInt(100000000
        )+1;
        int max = 100000000;
        int min = 1;
        int guessCount = 0;

        while(min <= max)
        {
            int mid = min + (max - min) /2;
            if(mid > target)
            {
                max = mid-1;
                guessCount++;
            }
            else if(mid < target)
            {
                min = mid + 1;
                guessCount++;
            }
            else {
                System.out.println("it is right  guess = " + mid);
                break;
            }
            System.out.println("target = " + target);
            System.out.println("guessCount = "  +guessCount);

        }
    }
}
